package com.asset.salesforce.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.asset.salesforce.model.File;

@Repository
public class FileDaoImpl {
	
	@Autowired
	private SessionFactory sessionFactory;
	
	public void addFile(File file) {
		try{
		sessionFactory.getCurrentSession().save(file);
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	public void saveOrupdate(File file){
		Session session = sessionFactory.getCurrentSession();
		session.saveOrUpdate(file);
	}

	@SuppressWarnings("unchecked")
	public List<File> getAllFile() {
		
		return sessionFactory.getCurrentSession().createQuery("from File").list();
		
		
	}
	@SuppressWarnings("unchecked")
	public File getFileById(Integer id) {
		return (File) sessionFactory.getCurrentSession().get(File.class, id);
	}

	public void deletefile(Integer id) {
		File file = (File) sessionFactory.getCurrentSession().load(
				File.class, id);
		if (null != file) {
			sessionFactory.getCurrentSession().delete(file);
		}
		
	}


}
